package com.aplikata.evok.dao;

import org.springframework.stereotype.Repository;

import com.aplikata.constants.ConstantsMsg;
import com.aplikata.dao.PublicDaoImpl;
import com.aplikata.evok.bo.Patient;
import com.aplikata.evok.bo.PatientTherapy;
import com.aplikata.evok.constants.EvokConstants;
import com.aplikata.exception.CustomException;
import com.aplikata.util.FacesUtil;

/** 
* @ClassName: PatientTherapyDaoImpl 
* @Description: TODO
* @author Huyun
* @date May 29, 2012 1:50:17 PM 
*  
*/
@Repository("patientTherapyDao")
public class PatientTherapyDaoImpl extends PublicDaoImpl<PatientTherapy, Long> implements PatientTherapyDao {

	@Override
	public boolean validate(PatientTherapy pt) throws Exception{
		if(pt == null)
			return false;
		
		if(pt.getDomainPatient() == null){
			throw new CustomException(ConstantsMsg.MSG_REQUIRE, new Object[] { FacesUtil.getMessage(Patient.LB_TITLE) });
		}
		
		if(pt.getType() == null){
			throw new CustomException(ConstantsMsg.MSG_REQUIRE, new Object[] { FacesUtil.getMessage(PatientTherapy.LB_TYPE) });
		}
		
		if(pt.getStatus() == null){
			throw new CustomException(ConstantsMsg.MSG_REQUIRE, new Object[] { FacesUtil.getMessage(PatientTherapy.LB_STATUS) });
		}
		
		if(pt.getStartDate() == null){
			throw new CustomException(ConstantsMsg.MSG_REQUIRE, new Object[] { FacesUtil.getMessage(PatientTherapy.LB_START_DATE) });
		}
		
		if(EvokConstants.PATIENT_THERAPY_STATUS_FINISH == pt.getStatus()){
			if(pt.getEndDate() == null){
				throw new CustomException(ConstantsMsg.MSG_REQUIRE, new Object[] { FacesUtil.getMessage(PatientTherapy.LB_END_DATE) });
			}
		}
		return true;
	}
}
